<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: reviews.php 140 2013-09-22 07:44:23Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 140 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:44:23 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if ($_SESSION['customers_status']['customers_status_read_reviews'] == 1) {
	$box_smarty = new smarty;
	$box_smarty->assign('tpl_path','templates/'.CURRENT_TEMPLATE.'/');
	$box_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');

	require_once(DIR_FS_INC.'inc.break_string.php');

	$fsk_lock='';
	if ($_SESSION['customers_status']['customers_fsk18_display']=='0')
		$fsk_lock=' AND p.products_fsk18 != 1';

	$random_select = "SELECT 
							r.reviews_id,
							r.reviews_rating,
							p.products_id,
							p.products_image,
							pd.products_name,
							languages_id
						FROM 
							".TABLE_REVIEWS." r,
							".TABLE_REVIEWS_DESCRIPTION." rd,
							".TABLE_PRODUCTS." p,
							".TABLE_PRODUCTS_DESCRIPTION." pd
						WHERE 
							p.products_status = '1'
						AND 
							p.products_id = r.products_id
							".$fsk_lock."
						AND 
							r.reviews_id = rd.reviews_id
						AND 
							r.reviews_status = '1'
						AND 
							rd.languages_id = '".(int)$_SESSION['languages_id']."'
						AND 
							p.products_id = pd.products_id
						AND 
							pd.language_id = '".(int)$_SESSION['languages_id']."'";

	if($product->isProduct())
		$random_select .= " AND p.products_id = '".$product->data['products_id']."'";

	$random_select .= " ORDER BY RAND() DESC";
	$random_product = $db->db_query_limit($random_select, MAX_RANDOM_SELECT_REVIEWS);


	if($random_product->_numOfRows) {
		$review = $db->db_query("SELECT
									SUBSTRING(reviews_text, 1, 60) AS reviews_text
								FROM
									".TABLE_REVIEWS_DESCRIPTION."
								WHERE
									reviews_id = '".$random_product->fields['reviews_id']."'
								AND
									languages_id = '".$_SESSION['languages_id']."'");

		$review = htmlspecialchars($review->fields['reviews_text']);
		$review = break_string($review, 15, '-<br />');
		
		$bild = DIR_WS_THUMBNAIL_IMAGES.'no_img.jpg';
		if($random_product->fields['products_image'] !='')
			$bild = '<img class="img_border" src="'.DIR_WS_THUMBNAIL_IMAGES.$random_product->fields['products_image'].'" alt="'.$random_product->fields['products_name'].'" />';

		$box_reviews = '<div class="ac">
							<a href="review-'.$random_product->fields['reviews_id'].'/'.get_url_friendly_text($random_product->fields['products_name']).'">';
		$box_reviews .= $bild;
		$box_reviews .= '	</a>
							</div>
							<a href="review-'.$random_product->fields['reviews_id'].'/'.get_url_friendly_text($random_product->fields['products_name']).'">'.$review.' ..</a><br />
							<div class="ac">
								'.image('templates/'.CURRENT_TEMPLATE.'/img/stars_'.$random_product->fields['reviews_rating'].'.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $random_product->fields['reviews_rating'])).'
							</div>';
	}

	if ($box_reviews!='') {
		$box_smarty->assign('REVIEWS_LINK',href_link(FILENAME_REVIEWS));
		$box_smarty->assign('BOX_CONTENT', $box_reviews);
		$box_smarty->assign('language', $_SESSION['language']);

		if (!CacheCheck()) {
			$box_smarty->caching = false;
			$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_reviews.html');
		} else {
			$box_smarty->caching = true;
			$box_smarty->cache_lifetime=CACHE_LIFETIME;
			$box_smarty->cache_modified_check=CACHE_CHECK;
			$cache_id = $_SESSION['language'].$random_product->fields['reviews_id'].$product->data['products_id'].$_SESSION['language'];
			$box_content = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_reviews.html',$cache_id);
		}
	}
}
?>